package two_shang._9_28;

import java.util.Random;
import java.util.Scanner;

public class BankCard {
    private int id;
    private String name;
    private Double money = 0.0;
    private String password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getMoney() {
        return money;
    }

    public void setMoney(Double money) {
        this.money = money;
    }

    public String getPassword() {
        return password;
    }

    public Boolean setPassword(String password) {
        if (password.length() == 6) {
            this.password = password;
            return true;
        } else {
            System.out.println("不是六位数字,请输入六位数密码");
            return false;
        }
    }

    public BankCard() {
    }

    public BankCard(String name, String password) {
        Random random = new Random();
        for (int i = 0; i < 1000; i++) {
            int a = random.nextInt(1000000);
            if (a > 99999) {
                this.id = a;
                break;
            }
        }
        this.name = name;
        if (setPassword(password)) {
            System.out.println("——————————————————————");
            System.out.println("银行卡创建成功!");
            System.out.println("你的姓名是：" + name + "  你的余额是：" + money);
            System.out.println("你的银行卡号：" + this.id);
            System.out.println("——————————————————————");
        } else {
            System.exit(1);
        }
    }

    public BankCard(String name, String password, Double money) {
        Random random = new Random();
        for (int i = 0; i < 1000; i++) {
            int a = random.nextInt(1000000);
            if (a > 99999) {
                this.id = a;
                break;
            }
        }
        this.name = name;
        if (setPassword(password)) {
            System.out.println("——————————————————————");
            System.out.println("银行卡创建成功!");
            System.out.println("你的姓名是：" + name + "  你的余额是：" + money);
            System.out.println("你的银行卡号：" + this.id);
            System.out.println("——————————————————————");
        } else {
            System.exit(1);
        }
    }

    public void deposit(double money) {
        if (money < 0) {
            System.out.println("不能输入负数!");
            return;
        }
        this.money += money;
        System.out.println("——————————————————————");
        System.out.println("你的余额是：" + this.money);
        System.out.println("——————————————————————");
    }

    public void withdraw(double money) {
        if (money < 0) {
            System.out.println("不能输入负数!");
            return;
        }
        if (money > this.money) {
            System.out.println("——————————————————————");
            System.out.println("你的余额不足");
            System.out.println("——————————————————————");
        } else {
            this.money -= money;
            System.out.println("——————————————————————");
            System.out.println("你的余额是：" + this.money);
            System.out.println("——————————————————————");
        }
    }

    public void queryM() {
        System.out.println("——————————————————————");
        System.out.println("你的余额是：" + this.money);
        System.out.println("——————————————————————");
    }

    public void queryP() {
        System.out.println("——————————————————————");
        System.out.println("你的密码是：" + password);
        System.out.println("——————————————————————");
    }

    public void swag(BankCard zhuan, double money) {
        zhuan.withdraw(money);
    }

    public void changePassword(String password) {
        if (password.equals(this.password)) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("验证成功，输入你要把密码改成什么:");
            setPassword(scanner.next());
        } else {
            System.out.println("验证失败");
        }
    }
}
